package processControl

fun main() {
    //if...else...
    var i = 0
    var j = 1
    if (i == j) {
        print("相等")
    } else {
        print("不相等")
    }

    //可以用以下写法替换jav中的...?...:...
    var str: String = if (i == j) "相等" else "不相等"

    var str_01 = when (i) {
        0, 2 -> "值为0或2"
        1 -> "值为1"
        in 10..20 -> "在10-20的范围内"
        is Int -> "是一个整形数字"
        else -> "以上条件都不满足"
    }

    //循环
    var list = mutableListOf<String>("a", "b", "c", "d")

    var myList = ArrayList<String>().apply { add("a") }

    //获取元素
    for (item in list) {
        print(item)
    }

    //获取下标
    for (i in list.indices) {
        print(list[i])
    }

    //左闭右开区间,包含10不包含20
    for (i in 10 until 20) {
        print(i)
    }

    //包含10和20,每次递增2
    for (i in 10..20 step 2) {
        print(i)
    }

    //递减
    for (i in 20 downTo 10) {
        print(i)
    }
}